package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

import java.util.UUID;

public class HoldSkill extends BaseSkill {
    public static UUID uuid = UUID.fromString("BCBE8A68-98B5-B3DE-E475-F8DFFA4489D3");

    public HoldSkill(int level) {
        super(level);
    }

    public HoldSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public HoldSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMaxlevel(10);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("匿踪技能，隐身。");
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    @Override
    public boolean passiveApply(MobEntity mobEntity) {
        EntityAttributeModifier modifier = new EntityAttributeModifier(uuid, getName(), getSkillLevel() / 10.0F, EntityAttributeModifier.Operation.fromId(0));
        EntityAttributeInstance entityAttributeInstance = mobEntity.getAttributeInstance(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE);
        if (entityAttributeInstance == null) return true;
        if (!entityAttributeInstance.hasModifier(modifier))
            entityAttributeInstance.addPersistentModifier(modifier);
        return true;
    }
}
